<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html><html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>物料类别管理</title>
    <style>
        .newtitle {
            PADDING-LEFT: 15px;
            BACKGROUND: url('');
            PADDING-BOTTOM: 4px;
            BORDER-LEFT: #c0dcf2 1px solid;
        }
    </style>
    <jsp:include page="easyuiIncludeJS.jsp"/>
    <script type="text/javascript">
        $(function () {
            var pager = $(".easyui-datagrid").datagrid('getPager');
            $(pager).pagination({
                total:${pager.totalRows},
                pageSize:${pager.pageRow},
                displayMsg: '{from}-{to}/{total}',
                pageNumber:${pager.cur_page},
                afterPageText: '页，共{pages}页',
                pageList: [30, 600, 900, 3000, 5000, 10000],
                loading: false,
                showPageList: true,
                showRefresh: true,
                //刷新方法
                onBeforeRefresh: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/materialType/list?cur_page=" + p + "&pageRow=" + s;
                },
                onSelectPage: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/materialType/list?cur_page=" + p + "&pageRow=" + s;
                }
            });
        });


        function edit(value, rec) {
            var materialTypeId = rec.materialTypeId;
            var materialTypeCode = rec.materialTypeCode;
            var materialTypeName = rec.materialTypeName;
            var formula = rec.formula;
            var url = "${pageContext.request.contextPath}/admin/materialType/json";
            $.post(
                url,
                {
                    "materialTypeId": materialTypeId,
                    "materialTypeCode": materialTypeCode,
                    "materialTypeName": materialTypeName,
                    "formula":formula
                },
                updemp,
                "json"
            );
        }

        function updemp(date) {
            $("#materialTypeId").val(date.materialTypeList.materialTypeId);
            $("#materialTypeCode").val(date.materialTypeList.materialTypeCode);
            $("#materialTypeName").val(date.materialTypeList.materialTypeName);
            $("#formula").val(date.materialTypeList.formula);
        }

        function add() {
            // if($("#statusName").textbox("getValue")==""){
            //     alert("请输入收费名称");
            //     $("#statusName").focus();
            //     return false;
            // }
            var url = "${pageContext.request.contextPath}/admin/materialType/add"
            var materialTypeId = $("#materialTypeId").val();
            var materialTypeCode = $("#materialTypeCode").val();
            var materialTypeName = $("#materialTypeName").val();
            var formula = $("#formula").val();
            if(materialTypeCode==""){
            	alert("请输入代码");
            	$("#materialTypeCode").focus();
            	return;
            }
            if(materialTypeName==""){
            	alert("请输入名称");
            	$("#materialTypeName").focus();
            	return;
            }
            
            $.post(
                url,

                {
                    "materialTypeId": materialTypeId,
                    "materialTypeCode": materialTypeCode,
                    "materialTypeName": materialTypeName,
                    "formula":formula
                },
                function (data) {
                    window.location.href = "${pageContext.request.contextPath }/admin/materialType/list";
                }
            )
        }
    </script>
</head>
<body>
<table class="easyui-datagrid" pagination="true" fitColumns="true" style="height:400px" singleSelect="true"
       data-options="onClickRow:edit">
    <thead>
    <tr>
        <th align="center" width="100" field="materialTypeId">编号</th>
        <th align="center" width="200" field="materialTypeCode">物料类别代码</th>
        <th align="center" width="200" field="materialTypeName">物料类别名称</th>
        <th align="center" width="200" field="formula">批号规则</th>
        <th align="center" width="200" field="opt">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${pager.datas}" var="d">
        <tr>
            <td>${d.materialTypeId}</td>
            <td>${d.materialTypeCode}</td>
            <td>${d.materialTypeName}</td>
            <td>${d.formula}</td>
            <td>
                <a href="${pageContext.request.contextPath}/admin/materialType/del?materialTypeId=${d.materialTypeId}" class="easyui-linkbutton" plain="true" icon="icon-remove"
                   onclick="return confirm('删除确定');"> 删除</a>
                <a href='javascript:void(0);' class="easyui-linkbutton" plain="true" icon="icon-undo" onclick='edit();'>编辑</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div id="tt" class="easyui-tabs" style="height:150px">
    <div title="物料类别管理" data-options="closable:false,cache:false" style="padding:0px;">
        <div class="newtitle">
            <th>
                <a class="easyui-linkbutton" plain="true" icon="icon-save" href="javascript:void(0);"
                   onclick="return add();">保存</a>
            </th>
        </div>
        <form name="form1" enctype="multipart/form-data" method="post">
            <hidden id="materialTypeId" name="materialTypeId"></hidden>
            <table width="100%" align="center" style="margin-top: 20px;">
                <tr>
                    <td align="right">物料类别代码：</td>
                    <td>
                        <input class="easyui-textbox" id="materialTypeCode" name="materialTypeCode"
                               data-options="prompt:'请输入物料类别代码',validType:'text'"><font color="red">必须唯一</font>
                    </td>
                    <td align="right">物料类别名称：</td>
                    <td>
                        <input class="easyui-textbox" id="materialTypeName" name="materialTypeName"
                               data-options="prompt:'请输入物料类别名称',validType:'text'">
                    </td>
                    <td align="right">批号规则：</td>
                    <td>
                        <input class="easyui-textbox" id="formula" name="formula"
                               data-options="prompt:'请输入批号规则',validType:'text'">
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
</body>
</html>
